/********************************************************************************
*		Primeiro Trabalho de Programacao Concorrente			*	
*	Programa para comprar a saida dos algoritmos com o pi correto		*
*										*
*	Alunos:									*
*		Felipe Augusto do Amaral (7239221)				*
*		Julio Cesar Gaban (7152872)					*
*		Tiago Santana de Nazare (7153118)				*
*										*
*	Execucao:								*
*		./<executavel> <pi_correto> <pi_gerado>				*
*										*
*	Compilacao:								*
*		gcc <fonte> -o <executavel> -ansi -Wall				*
*********************************************************************************/

#include <stdio.h>

int main(int argc, char *argv[]){
	FILE 	*pi1 = fopen (argv[1], "r"), 
		*pi2 = fopen (argv[2], "r");
	char	bufferPi1[100],
		bufferPi2[100];
	unsigned long int acertos = 0;
	int i, sair = 0;

	/* Compara os buffers ate ter alguma diferenca ou ate um arquivo terminar */
	while(sair == 0 && fgets(bufferPi1, 100, pi1) != NULL && fgets(bufferPi2, 100, pi2) != NULL){
		for(i = 0; i < 100; ++i){
			if(bufferPi1[i] != bufferPi2[i]){
				sair = 1;
				break;
			}
			++acertos;
		}
	}

	cnt = ((cnt > 2) ? cnt - 2 : 0);

	/* Imprime a quantidade de digitos corretos e os buffers */
	printf("digitos corretos %ld\n", acertos);
	bufferPi1[99] = bufferPi2[99] = '\0';
	printf("buffer 1 = %s\n", bufferPi1);
	printf("buffer 2 = %s\n", bufferPi2);

	fclose(pi1);
	fclose(pi2);
	return 0;
}
